package com.zr.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionSupport;
import com.zr.model.Cuser;
import com.zr.service.TreeService;

import net.sf.json.JSONArray;

@Controller
@Scope(value="prototype")
public class TreeAction extends ActionSupport implements ServletResponseAware,SessionAware{
	
   private HttpServletResponse resp;
   private Map<String, Object> session;
   
   @Resource
   private TreeService treeService;
   
	@Override
	public void setServletResponse(HttpServletResponse arg0) {
		this.resp=arg0;
	}
	@Override
	public void setSession(Map<String, Object> arg0) {
		this.session=arg0;
	}
	public void tree(){
		resp.setCharacterEncoding("utf8");
		Cuser user=(Cuser)session.get("cuser");
		String fid=treeService.getpidByuid(user.getUid());
		JSONArray js=treeService.getFunctionsByPid(-1, fid);
		PrintWriter out;
		try {
			out = resp.getWriter();
			out.write(js.toString());
			out.flush();
			out.close();
		} catch (IOException e) {
		
			e.printStackTrace();
		}	
	}
	

}
